package applicationPlugin;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.URI;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.JScrollPane.*;
import javax.swing.border.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

import interfacesplugins.InterfaceFilesTraitement;
import interfacesplugins.InterfacePlugins;

public class Browser extends JFrame implements
		InterfaceFilesTraitement {

	/**
	 * 
	 */private boolean etat;
	private static final long serialVersionUID = 1L;
	JEditorPane htmlPane;
	String r;
	private File file;

	public Browser() {
		setBounds(0, 0, 1000, 700);
		etat=true;
	}

	public void lireHtml(File f) {
		
	        try{
	                InputStream ips=new FileInputStream(f); 
	                InputStreamReader ipsr=new InputStreamReader(ips);
	                BufferedReader br=new BufferedReader(ipsr);
	                
	                String ligne;
	                while ((ligne=br.readLine())!=null){
	                        
	                        if(ligne.toLowerCase().matches("url.*")){
	                            
	                ligne = ligne.substring(4, ligne.length());
	                Desktop Bureau = Desktop.getDesktop();
	                URI url = new URI(ligne);
	                                Bureau.browse(url);
	        }
	                }
	                
	                br.close(); 
	        }               
	        catch (Exception e){
	                System.out.println(e.toString());
	        }
	        
	}

	@Override
	public String getNomPlugin() {
		// TODO Auto-generated method stub
		return "JTree Web Browser";
	}

	@Override
	public String getVersion() {
		// TODO Auto-generated method stub
		return "1.0";
	}

	@Override
	public String getDeveloppeur() {
		// TODO Auto-generated method stub
		return "EL MALLEM AMINE";
	}

	@Override
	public String[] getExtension() {
		// TODO Auto-generated method stub
		String[] s = { "html", "htm" };
		return s;
	}

	@Override
	public JFrame lancerFichier(File f) {
		// TODO Auto-generated method stub
		Browser e = new Browser();
		this.file=f;
		this.etat=true;
		e.lireHtml(f);
		e.setVisible(true);
		return e;
	}
	
	

	@Override
	public boolean getEtat() {
		// TODO Auto-generated method stub
		return etat;
	}

	@Override
	public boolean setEtat(boolean etat) {
		// TODO Auto-generated method stub
		this.etat=etat;
		return etat;
	}
}
